#include <bits/stdc++.h>
using namespace std;

int sum, n; // sum: 总需求量, n: 农民数量
struct Farmer {
    int price, supply;  // 牛奶单价和供应量
};
vector<Farmer> farmers;

// 排序规则：单价低的优先，单价相同则供应量大的优先
bool cmp(const Farmer &a, const Farmer &b) {
    if (a.price == b.price) return a.supply > b.supply;
    return a.price < b.price;
}

int main() {
    cin >> sum >> n;
    // 读取农民数据
    for (int i = 0; i < n; i++) {
        int p, s;
        cin >> p >> s;
        farmers.push_back({p, s});
    }
    
    // 按贪心策略排序：优先选单价低的农民
    sort(farmers.begin(), farmers.end(), cmp);
    
    int remaining = sum, cost = 0; // remaining: 剩余需购买量
    // 遍历排序后的农民列表
    for (auto &f : farmers) {
        if (remaining <= 0) break; // 已满足需求
        
        // 全量购买当前农民的牛奶
        if (f.supply <= remaining) {
            cost += f.price * f.supply;
            remaining -= f.supply;
        } 
        // 部分购买当前农民的牛奶
        else {  
            cost += f.price * remaining;
            remaining = 0;
            break; // 已满足需求，提前退出
        }
    }
    cout << cost << endl;
    return 0;
}